
const express = require('express');
const router = express.Router()

// 判断用户有没有登录
router.use((req, res, next) => {
  if(req.session.userInfo && req.session.userInfo.username) {
    next()
  } else {
    // next()
    var pathname = url.parse(req.url).pathname
    if(pathname === '/login' || pathname === '/login/doLogin' || pathname === '/login/verify') {
      next()
    } else {
      res.redirect('/admin/login')
    }
  }
})

// 引入模块
const main = require('./admin/main')
const user = require('./admin/user')
const login = require('./admin/login')
const nav = require('./admin/nav')
const manager = require('./admin/manager')
const focus = require('./admin/focus')

const url = require('url')
// router.get('/', function (req, res) {
//   res.send('后台管理中心')
// })

// 挂载路由
router.use('/', main)
router.use('/user', user)
router.use('/login', login)
router.use('/nav', nav)
router.use('/manager', manager)
router.use('/focus', focus)

module.exports = router
